<?php
/**
 * RAI IP 验证类
 *
 * @version $Id: RaiIpValidator.php 312 2008-04-23 16:29:38Z iwind $
 * @package net.4kiki.rai.server.validator
 * @since 0.0.3
 */
class RaiIpValidator extends  AbstractRaiValidator {
	private $validIps = array();
	private $currentIp;
	private $fault;
	
	public function __construct($validIps = null, $currentIp = null) {
		if (is_array($validIps)) {
			$this->validIps = $validIps;
		}
		else {
			if ($validIps !== null) {
				throw new RaiException("valid ip list must be an array");
			}
		}
		$this->currentIp = $currentIp;
	}
	
	public function validate() {
		if (!empty($this->validIps)) {
			if (!in_array($this->currentIp, $this->validIps)) {
				$this->setFault(new RaiFault(5001, "ip validate failed"));
				return false;
			}
		}
		return true;
	}
}

?>